--# fl_GuildBot
--#############################################
--# Automates tasks in the World of Warcraft
--#  FEATURES:
--#    * Congratulates people in guild who get achievements!
--#
--#############################################
--# CONFIGURATION
--###
	--Nothing yet to configure!
--###
--# END CONFIGURATION
--#############################################
--# EDITING BELOW HERE MAY CAUSE THE ADDON TO NOT WORK!
--# EDIT AT YOUR OWN RISK!!
--###

	local time = 0;
	local timesrun = 1;
	
--###  3.1 ~ Ulduar Craftables : Alliance
	
	local function AutoCongrats(player)
		SendChatMessage("Congratulations " .. player .. ", on your achievement!", "GUILD", "COMMON");
		--SendChatMessage("Congratulations on the achievement!", "WHISPER", "COMMON", player);
		DEFAULT_CHAT_FRAME:AddMessage("[fl_AutoBot]: " .. player .." got an achievement!");
	end
	
	local function AutoWelcome(player)
		SendChatMessage("Welcome to the guild " .. player .. "!", "GUILD", "COMMON");
	end
	
	local function AutoFarewell(player)
		SendChatMessage("Sad to see " .. player .. " leave.. =(", "GUILD", "COMMON");
		SendChatMessage("Sad to see you leave the guild, " .. player, "WHISPER", "COMMON", player);
	end
	
--###
	
	function fl_AutoBot_OnLoad()
		DEFAULT_CHAT_FRAME:AddMessage("[fl_AutoBot]: Loaded! Time to make life easy.", 0.4, 0.4, 1.0);
		this:RegisterEvent("CHAT_MSG_GUILD_ACHIEVEMENT");
		--this:RegisterEvent("CHAT_MSG_SYSTEM");
	end

	function AutoBotAchieveGrats_OnEvent()
		if (event == "CHAT_MSG_GUILD_ACHIEVEMENT") then
			AutoCongrats(arg5);
		end
	end
	
	function AutoBotJoinsGuild_OnEvent()
		if (event == "ERR_GUILD_JOIN_S") then
			start, player = string.find(arg1, "(.+) has joined the guild.");
			if(start) then
				AutoWelcome(player);
			end
		end
	end
	
	function AutoBotLeavesGuild_OnEvent()
		if (event == "ERR_GUILD_LEAVE_S") then
			start, player = string.find(arg1, "(.+) has left the guild.");
			if(start) then
				AutoFarewell(player);
			end
		end
	end
	
--###
--# EDIT THE ABOVE AT YOUR OWN RISK
--##############################################
--# fl_AutoBot 
--##############################################